package com.yodawnla.quickCard.card;

import org.anddev.andengine.entity.Entity;
import org.anddev.andengine.entity.sprite.Sprite;

import android.util.Log;

import com.yodawnla.lib.YoActivity;
import com.yodawnla.lib.util.widget.YoText;
import com.yodawnla.quickCard.system.Fonts;
import com.yodawnla.quickCard.system.Values;

public class DetailCard extends Sprite
{
	Entity mImgHolder;
	int mCardType;
	YoText mName;
	YoText mPt;
	Sprite mImg;
	Sprite mNameTag;
	Sprite mPtBg;
	CardInfo mInfo;
	int mTextureIndex;
	
	DeckManager mDeckMgr;
	
	static final int TEXT_Y = 325; // 318
	
	public DetailCard(float pX, float pY)
	{
		super(pX, pY, YoActivity.getBaseActivity().getTexture("BigCard"));
		
		mDeckMgr = DeckManager.getInstance();
		
		mImgHolder = new Entity();
		this.attachChild(mImgHolder);
		
		mNameTag = new Sprite(0, 305, YoActivity.getBaseActivity().getTexture("NameTag"));
		this.attachChild(mNameTag);
		
		mPtBg = new Sprite(164, 5, YoActivity.getBaseActivity().getTexture("PtBg"));
		this.attachChild(mPtBg);

		mName = new YoText(50, TEXT_Y, Fonts.Black20, "name", 20);
		this.attachChild(mName);
		
		mPt = new YoText(190, 25, Fonts.Black20, "2", 2);
		this.attachChild(mPt);
	}
	
	public void setCardType(final int cardType)
	{
		mCardType = cardType;
//		Log.e("DetailCard", "set card type : "+ cardType);
		mInfo = mDeckMgr.getCardInfo(cardType);
		
		mName.setText(mInfo.getName());
		
		mName.setPosition((this.getWidth() - mName.getWidth()) /2 , TEXT_Y);
		
		mPt.setText(""+mInfo.getPt());
		
		YoActivity.getBaseActivity().runOnUiThread(new Runnable() 
		{
            public void run() 
            {
            	if (mImg != null)
            	{
            		mImg.reset();
	            	mImg.setPosition(-10000, -10000);
	            	mImg.setVisible(false);
	            	mImg.detachSelf();
            	}
            	
            	if (cardType < Values.Card.TOTAL_CARD_KINDS)
            	{
            		mTextureIndex = 1+cardType;
        			mImg = new Sprite(4, 4 ,YoActivity.getBaseActivity().getTexture("B"+mTextureIndex));
            	}
        		else
        		{
        			int index = cardType - (Values.Card.EX_CARD_START - Values.Card.TOTAL_CARD_KINDS);
        			mTextureIndex = 1+index;
        			mImg = new Sprite(4, 4 ,YoActivity.getBaseActivity().getTexture("B"+mTextureIndex));
        		}
            	mImgHolder.attachChild(mImg);
            }
		});
	}
	
	public int getTextureIndex()
	{
		return mTextureIndex;
	}

	public int getCardType()
	{
		return mCardType;
	}
	
	public int getGoldCost()
	{
		return mInfo.getGoldCost();
	}
	
	public int getSilverCost()
	{
		return mInfo.getSilverCost();
	}
	
	public int getCopperCost()
	{
		return mInfo.getCopperCost();
	}
	
	public String getHeroName()
	{
		return mInfo.getHeroName();
	}

	public String getStory()
	{
		return mInfo.getStory();
	}
}
